import matplotlib.pyplot as plt
import numpy as np

y1 = [75.96, 69.66, 66.94, 59.67, 50.49, 42.17, 41.83, 36.55, 31.23, 32.99]
y2 = [78.65, 75.26, 74.61, 66.67, 55.54, 47.85, 45.65, 41.32, 32.66, 34.13]
y3 = [75.42, 77.22, 71.85, 68.16, 58.57, 48.62, 39.89, 32.99, 29.28, 31.05]
y4 = [79.06, 76.68, 76.8, 68.03, 55.54, 47.85, 45.65, 41.32, 32.66, 34.13]
y5 = [77.48, 77.03, 70.28, 63.74, 58.57, 48.62, 39.89, 32.99, 29.28, 31.05]


def plt_bar(title, y1, y2, y3, y4, y5):
    plt.rcParams['savefig.dpi'] = 300  # 图片像素
    plt.rcParams['figure.dpi'] = 300  # 分辨率
    plt.rcParams['figure.figsize'] = (4, 3)  # 尺寸
    plt.title(title)

    name = ['24', '48', '72', '96', '120', '144', "168", "192", "216", "240"]
    x = np.arange(len(name)) * 3
    width = 0.5

    plt.bar(x, y1, width=width, label='scmoc', color='green')
    plt.bar(x + width, y2, width=width, label='revise', color='deepskyblue', tick_label=name)
    plt.bar(x + 2 * width, y3, width=width, label='re+bc', color='blue')
    plt.bar(x + 3 * width, y4, width=width, label='revise12', color='yellow')
    plt.bar(x + 4 * width, y5, width=width, label='re12+bc', color='red')

    # 显示在图形上的值
    for a, b in zip(x, y1):
        plt.text(a, b + 0.1, round(b,1), ha='center', va='bottom', fontsize=8)
    for a, b in zip(x, y2):
        plt.text(a + width, b + 0.1, round(b,1), ha='center', va='bottom', fontsize=8)
    for a, b in zip(x, y3):
        plt.text(a + 2 * width, b + 0.1, round(b,1), ha='center', va='bottom', fontsize=8)
    for a, b in zip(x, y4):
        plt.text(a + 3 * width, b + 0.1, round(b,1), ha='center', va='bottom', fontsize=8)
    for a, b in zip(x, y5):
        plt.text(a + 4 * width, b + 0.1, round(b,1), ha='center', va='bottom', fontsize=8)

    plt.xticks()
    plt.legend(loc="upper right")  # 防止label和图像重合显示不出来
    # plt.rcParams['font.sans-serif'] = ['SimHei']  # 用来正常显示中文标签
    plt.ylabel('score')
    plt.xlabel('time')

    plt.savefig(f'/home/gym/projects/modelDeploy/result/{title}.png')
    # plt.show()
    plt.close()


if __name__ == '__main__':
    plt_bar('test', y1, y2, y3, y4, y5)
